package com.apes.hr.recruit.repository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.hr.base.model.Employee;
import com.apes.hr.recruit.model.ApplyJobOrder;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author HuJianLin
 * @create 2018-04-28 16:07
 */
public interface ApplyJobOrderRepository extends CustomRepository<ApplyJobOrder, String>{


    @Query(value = "select A.* from hr_Apply_Job_Order A " +
            "where A.employee_id LIKE  %:value% AND A.state = :state and a.invoking = '0' " , nativeQuery = true)
    List<ApplyJobOrder> findByEmployeeAndState(@Param("value")String ID, @Param("state") String state);

    List<ApplyJobOrder> findByEmployee(Employee employee);

    @Query(value = "select A.* from hr_Apply_Job_Order A ," +
            "(SELECT MAX(F.CREATE_DATE) CREATE_DATE  FROM HR_APPLY_JOB_ORDER F GROUP BY F.EMPLOYEE_ID ) G" +
            "    WHERE A.CREATE_DATE =G.CREATE_DATE  " +
            "And A.employee_id LIKE  %:value%  " , nativeQuery = true)
    List<ApplyJobOrder> findByEmployee(@Param("value")String ID);

    List<ApplyJobOrder> findByBranchIdAndWorkPostIdAndState(String branchId,String workPostId,String state);

}
